import { Injectable } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { QueryOptions } from 'src/app/project/model/common/query-options';
import { Observable } from 'rxjs';
import { ApiPagedData } from 'src/app/project/model/common/api-paged-data';
import { StudentCreditRecordDTO } from 'src/app/project/model/icm/icm-student-status/academic-progress/student-credit-record.dto';

@Injectable({
  providedIn: 'root',
})
export class StudentCreditRecordService {
  private static URL = '/api/icm-credit-record';

  constructor(private http: _HttpClient) {}

  /**
   * 分页查找学生学分记录
   * @param option 分页参数
   * @param academyId 学院名称
   * @param professionId 专业名称
   * @param classId 班级名称
   * @param studentName 学生姓名
   * @param grade 年级，即入学年份
   */
  findOnePage(
    option: QueryOptions,
    academyId?: string,
    professionId?: string,
    classId?: string,
    studentName?: string,
    grade?: string,
  ): Observable<ApiPagedData<StudentCreditRecordDTO>> {
    const params = {};
    Object.assign(
      params,
      option,
      academyId ? { academyId } : {},
      professionId ? { professionId } : {},
      classId ? { classId } : {},
      studentName ? { studentName } : {},
      grade ? { grade } : {},
    );
    return this.http.get<ApiPagedData<StudentCreditRecordDTO>>(StudentCreditRecordService.URL, params);
  }

  /**
   * 根据id查找学生学分记录
   * @param id 学生学分记录id
   */
  findById(id: string): Observable<StudentCreditRecordDTO> {
    return this.http.get<StudentCreditRecordDTO>(`${StudentCreditRecordService.URL}/${id}`);
  }

  /**
   * 根据学生学号查找学生学分记录
   * @param studentCode 学生code
   */
  findByStudentCode(studentCode: string): Observable<StudentCreditRecordDTO> {
    return this.http.get<StudentCreditRecordDTO>(`${StudentCreditRecordService.URL}/code/${studentCode}`);
  }

  /**
   * 提交学生学分记录
   * @param id 学生学分记录id
   * @param studentCreditRecordDTO 学生学分记录
   */
  complete(id: string, studentCreditRecordDTO: StudentCreditRecordDTO): Observable<StudentCreditRecordDTO> {
    return this.http.put<StudentCreditRecordDTO>(`${StudentCreditRecordService.URL}/${id}`, studentCreditRecordDTO);
  }
}
